#ifndef _REPL_H_
#define _REPL_H_

static const char *REPL =
	"local silly = require 'silly'\n"
	"local assert = assert\n"
	"local function execute_line(code, buffer)\n"
	"	if buffer ~= '' then\n"
	"		code = buffer .. '\\n' .. code\n"
	"	end\n"
	"	local chunk, error = load(code)\n"
	"	if chunk then\n"
	"		local success, result = pcall(chunk)\n"
	"		if success then\n"
	"			if result ~= nil then\n"
	"				print(result)\n"
	"			end\n"
	"			return true, ''\n"
	"		else\n"
	"			print('Error: ' .. result)\n"
	"			return true, ''\n"
	"		end\n"
	"	else\n"
	"		assert(error)\n"
	"		if error:match('<eof>') then\n"
	"			return false, code\n"
	"		else\n"
	"			print('Syntax error: ' .. error)\n"
	"			return true, ''\n"
	"		end\n"
	"	end\n"
	"end\n"
	"print(string.format('Welcome to Silly %s, built on %s',\n"
	"	silly.version, _VERSION))\n"
	"local buffer = ''\n"
	"local prompt = function()\n"
	"	if buffer == '' then\n"
	"		return '> '\n"
	"	else\n"
	"		return '>> '\n"
	"	end\n"
	"end\n"
	"io.write(prompt())\n"
	"for line in io.stdin:lines() do\n"
	"	line = line:match('^%s*(.-)%s*$')\n"
	"	if line ~= '' then\n"
	"		local complete, new_buffer = execute_line(line, buffer)\n"
	"		buffer = new_buffer\n"
	"	end\n"
	"	io.write(prompt())\n"
	"	io.flush()\n"
	"end\n"
	"silly.exit(0)";

#endif